<div class="weadmin-body layui-main" id="app">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="we-red">*</span>名称
            </label>
            <div class="layui-input-block">
                <input type="text" id="name" name="name" lay-verify="required" autocomplete="off" class="layui-input" value="<?php echo $name ?>">
            </div>
        </div>
        <?php if (!empty($pid)):?>
            <div class="layui-form-item layui-form-text">
                <label for="thumb" class="layui-form-label">缩略图</label>
                <div class="layui-input-inline">
                    <div class="layui-upload-drag" id="thumb_eara">
                        <i class="layui-icon"></i>
                        <p>点击上传，或将文件拖拽到此处</p>
                    </div>
                </div>
                <div class="layui-input-inline" v-if="thumb_sign||'<?php echo $thumb_src?>'">
                    <img :src="thumb_src" width="180" height="180">
                    <input type="hidden" name="thumb_sign" v-model="thumb_sign" class="layui-input">
                </div>
            </div>
        <?php else:?>
            <div class="layui-form-item layui-form-text">
                <label for="app_id" class="layui-form-label">所属应用</label>
                <div class="layui-input-inline">
                    <select name="app_id" id="app_id">
                        <option value="0">请选择</option>
                        <?php foreach ($app_list as $app):
                            $select = $app['AgentId'] == $app_id ? 'selected="selected"' : '';
                            ?>
                            <option value="<?php echo $app['AgentId'] ?>" <?php echo $select?>><?php echo $app['app_name']?></option>
                        <?php endforeach;?>
                    </select>
                </div>
            </div>
        <?php endif;?>
        <div class="layui-form-item layui-form-text">
            <label for="note" class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" id="note" name="note" class="layui-textarea"><?php echo $note ?></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="modify" lay-submit="">编辑</button>
        </div>
        <input type="hidden" name="id" value="<?php echo $id ?>">
    </form>
</div>
<script src="<?php echo Yii::app()->baseUrl?>/static/vue/vue.min.js"></script>
<script>
    var app = new Vue({
        el:'#app',
        data:{
            thumb_sign:'',
            thumb_src:'<?php echo Yii::app()->baseUrl.$thumb_src?>'
        }
    });
    layui.use(['form', 'jquery', 'layer','upload'], function() {
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;
        var upload = layui.upload;
        //监听提交
        form.on('submit(modify)', function(data) {
            $.post('<?php $this->createUrl('floder/modify')?>', data.field,function (ret) {
                if (ret.code == 0) {
                    layer.msg('编辑成功!',{icon: 1,time:1000}, function () {
                        if (window == window.top) {
                            $('form')[0].reset();
                        } else {
                            var index = window.parent.layer.getFrameIndex(window.name);
                            window.parent.layer.close(index);
                            window.parent.location.reload();//刷新父界面
                        }
                    });
                } else {
                    layer.alert(ret.message);
                }
            });
            return false;
        });

        //拖拽上传
        upload.render({
            elem: '#thumb_eara',
            url: '<?php echo $this->createUrl('floder/uploadThumb')?>',
            done: function(res){
                if (res.code != 0) {
                    layer.msg(res.message, {time: 3000, icon: 2});
                } else {
                    app.thumb_sign = res.data;
                    app.thumb_src = '<?php echo Yii::app()->baseUrl?>/upload/'+res.data;
                    layer.msg(res.message, {time: 1000, icon: 1});
                }
            }
        });
    });
</script>
